package com.microinvest.service.impl;

import com.microinvest.dao.UserGetMapper;
import com.microinvest.entity.BuyStock;
import com.microinvest.entity.SellStock;
import com.microinvest.entity.UserStockFavorites;
import com.microinvest.service.UserGetService;
import com.microinvest.util.Result;
import com.microinvest.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class UserGetServiceImpl implements UserGetService {

    private final UserGetMapper userGetMapper;

    @Autowired
    public UserGetServiceImpl(UserGetMapper userGetMapper){
        this.userGetMapper=userGetMapper;
    }

    //返回用户收藏信息
    @Override
    public Result<List<UserStockFavorites>> getUserStockFavorites() {
       Map<String,Integer> map =ThreadLocalUtil.get();
       int userId=map.get("userId");
       List<UserStockFavorites> userStockFavorites=userGetMapper.GetUserStockFavorites(userId);
       return Result.success(userStockFavorites);
    }

    //返回用户购买信息
    @Override
    public Result<List<BuyStock>> getUserBuyStock() {
        Map<String,Integer> map =ThreadLocalUtil.get();
        int userId=map.get("userId");
        List<BuyStock> userBuyStockInfo=userGetMapper.GetUserBuyStockInfo(userId);
        return Result.success(userBuyStockInfo);
    }

    //返回用户卖出信息
    @Override
    public Result<List<SellStock>> getUserSellStock() {
        Map<String,Integer> map =ThreadLocalUtil.get();
        int userId=map.get("userId");
        List<SellStock> userSellStockInfo=userGetMapper.GetUserSellStockInfo(userId);
        return Result.success(userSellStockInfo);
    }
}
